package com.xhwl.logistics.component;


import com.xhwl.common.pojo.cent.device.DeviceProduct;
import com.xhwl.logistics.enums.*;
import com.xhwl.logistics.service.cent.IDeviceService;
import com.xhwl.logistics.util.EnumDynamicUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * 初始化后，动态生成枚举类中的枚举值
 */
@Slf4j
@Component
public class InitEnumRunner implements CommandLineRunner {

    @Autowired
    private IDeviceService iDeviceService;

    @Override
    public void run(String... args) throws Exception {
        EnumDynamicUtil enumDynamicUtil = new EnumDynamicUtil();
        List<DeviceProduct> deviceProductList = iDeviceService.list();
        //将大华ICC平台的productId与对应的实现类进行绑定
        DeviceProduct deviceProduct = deviceProductList.stream().filter(s -> {
            if (s.getName().contains("大华ICC平台")) {
                return true;
            } else {
                return false;
            }
        }).findAny().orElse(null);
        if(deviceProduct!=null){
            EnumDynamicUtil.addEnum(VehicleParkingLotHandlerEnum.class,"VEHICLE_PARKINGLOT_DAHUA_ICC",new Class<?>[]{Integer.class,String.class},new Object[]{deviceProduct.getId(),"vehicleParkingLotDaHuaIccHandlerImpl"});
            EnumDynamicUtil.addEnum(VehicleParkingLotSyncHandlerEnum.class,"VEHICLE_PARKINGLOT_DAHUA_ICC",new Class<?>[]{Integer.class,String.class},new Object[]{deviceProduct.getId(),"vehicleParkingLotDaHuaIccSyncHandlerImpl"});
            EnumDynamicUtil.addEnum(VehicleParkingLotCarAuthEnum.class,"VEHICLE_PARKINGLOT_DAHUA_ICC",new Class<?>[]{Integer.class,String.class},new Object[]{deviceProduct.getId(),"vehicleParkingLotDaHuaIccCarAuthHandlerImpl"});
            EnumDynamicUtil.addEnum(VehicleParkingLotStatisticsHandlerEnum.class,
                    "VEHICLE_PARKINGLOT_DAHUA_ICC",
                    new Class<?>[]{Integer.class,String.class},
                    new Object[]{deviceProduct.getId(),"vehicleParkingLotDaHuaIccStatisticsHandlerImpl"});
            EnumDynamicUtil.addEnum(VehicleDeviceHandlerEnum.class,
                    "VEHICLE_PARKINGLOT_DAHUA_ICC",
                    new Class<?>[]{Integer.class, String.class},
                    new Object[]{deviceProduct.getId(), "vehicleParkingLotDaHuaDeviceHandlerImpl"});
        }

        //科松配置绑定
        DeviceProduct deviceProduct1 = deviceProductList.stream().filter(s -> {
            if (s.getName().contains("科松-车场系统")) {
                return true;
            } else {
                return false;
            }
        }).findAny().orElse(null);
        if(deviceProduct1!=null){
            EnumDynamicUtil.addEnum(VehicleParkingLotHandlerEnum.class,"VEHICLE_PARKINGLOT_COSON",new Class<?>[]{Integer.class,String.class},new Object[]{deviceProduct1.getId(),"vehicleParkingLotCoSonHandlerImpl"});
            EnumDynamicUtil.addEnum(VehicleDeviceHandlerEnum.class,"VEHICLE_DEVICE_COSON",new Class<?>[]{Integer.class,String.class},new Object[]{deviceProduct1.getId(),"vehicleParkingLotCoSonDeviceHandlerImpl"});
        }

        /**
         * 兴海自研（创享绑定）
         */
        DeviceProduct deviceProductChuangXiang = deviceProductList.stream().filter(s -> {
            if (s.getName().contains("兴海物联自研车行")) {
                return true;
            } else {
                return false;
            }
        }).findAny().orElse(null);
        if(deviceProductChuangXiang!=null){
            EnumDynamicUtil.addEnum(VehicleParkingLotHandlerEnum.class,
                    "VEHICLE_PARKINGLOT_CHUANG_XIANG",
                    new Class<?>[]{Integer.class, String.class},
                    new Object[]{deviceProductChuangXiang.getId(), "vehicleParkingLotChuangXiangHandlerImpl"});
            EnumDynamicUtil.addEnum(VehicleParkingLotSyncHandlerEnum.class,
                    "VEHICLE_PARKINGLOT_CHUANG_XIANG",
                    new Class<?>[]{Integer.class, String.class},
                    new Object[]{deviceProductChuangXiang.getId(), "vehicleParkingLotChuangXiangSyncHandlerImpl"});
            EnumDynamicUtil.addEnum(VehicleParkingLotCarAuthEnum.class,
                    "VEHICLE_PARKINGLOT_CHUANG_XIANG",
                    new Class<?>[]{Integer.class, String.class},
                    new Object[]{deviceProductChuangXiang.getId(), "vehicleParkingLotChuangXiangCarAuthHandlerImpl"});
        }

        /**
         * 科拓
         */
        DeviceProduct deviceProductKeTop = deviceProductList.stream().filter(s -> {
            if (s.getName().contains("科拓-车场系统")) {
                return true;
            } else {
                return false;
            }
        }).findAny().orElse(null);
        if(deviceProductKeTop!=null){
            EnumDynamicUtil.addEnum(VehicleParkingLotCarAuthEnum.class,
                    "VEHICLE_PARKINGLOT_KETOP",
                    new Class<?>[]{Integer.class,String.class},
                    new Object[]{deviceProductKeTop.getId(),
                    "vehicleParkingLotKeTopCarAuthHandlerImpl"});
        }
    }


}